<template>
  <div class="photo-list">
    <!-- 顶部导航块 -->
    <div id="slider" class="mui-slider">
      <div
        id="sliderSegmentedControl"
        class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted"
      >
        <div class="mui-scroll">
          <a
            :class="['mui-control-item', item.id==0?'mui-active':'']"
            v-for="(item) in categoryList"
            :key="item.id"
            @click.prevent="getPhotoList(item.id)"
          >{{item.title}}</a>
        </div>
      </div>
    </div>

    <!-- 图片列表 -->
    <div class="list">
      <ul>
        <router-link
          tag="li"
          :to="'/home/photoinfo/' + item.id"
          v-for="item in photoList"
          :key="item.img_url"
        >
          <img v-lazy="item.img_url">
          <div class="info">
            <h1>{{item.title}}</h1>
            <p>{{item.zhaiyao}}</p>
          </div>
        </router-link>
      </ul>
    </div>
  </div>
</template>
  

<script>
import mui from "../../lib/mui/js/mui.min.js";
export default {
  data() {
    return {
      categoryList: [],
      photoList: [],
      id: 0
    };
  },
  created() {
    this.getCategory();
    this.getPhotoList(0);
  },
  mounted() {
    mui(".mui-scroll-wrapper").scroll({
      deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
    });
  },
  methods: {
    getCategory() {
      this.$http.get("api/getimgcategory").then(rs => {
        let data = rs.body;
        console.log(data);
        if (data.status === 0) {
          this.categoryList = data.message;
          this.categoryList.unshift({
            id: 0,
            title: "全部"
          });
        }
      });
    },
    getPhotoList(id) {
      this.$http.get("api/getimages/" + id).then(rs => {
        let data = rs.body;

        if (data.status === 0) {
          this.photoList = data.message;
        }
      });
    }
  }
};
</script>   


<style lang="scss" scoped>
* {
  touch-action: pan-y;
}
.photo-list {
  .list {
    ul {
      margin: 0;
      padding: 10px;
      padding-bottom: 0px;
      list-style: none;
      li {
        background: #ccc;
        text-align: center;
        margin-bottom: 10px;
        box-shadow: 0 0 4px rgba(0, 0, 0, 0.3);
        position: relative;
        img {
          width: 100%;
          vertical-align: middle;
        }
        img[lazy="loading"] {
          width: 40px;
          height: 300px;
          margin: auto;
        }
        .info {
          position: absolute;
          bottom: 0;
          background: rgba(0, 0, 0, 0.3);
          color: #fff;
          text-align: left;
          height: 100px;
          padding: 0 5px;
          overflow: hidden;
          h1 {
            font-size: 14px;
            margin: 3px 0px;
          }
          p {
            font-size: 13px;
            color: #fff;
          }
        }
      }
    }
  }
}
</style>
